<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            height: 700px;
            border: 2px solid red;
            perspective: 1000px;
        }

        .mybox {
            width: 400px;
            height: 300px;
            border: 2px solid blue;
            margin: 200px auto 0;
            transform-style: preserve-3d;
            /* 可不加 因为有上面的transform-style: preserve-3d; */
            position: relative;
        }

        .mybox:hover {
            /* 中心旋转 防止视觉放大 */
            transform-origin: 50% 50% -100px;
            transform:  rotateY(180deg);
            transition: all 6s ease ;
        }

        .face {
            position: absolute;
            left: 0;
            top: 0;
        }

        .before,
        .after {
            width: 400px;
            height: 300px;
        }

        .before {
            background-color: rgba(240, 224, 79, 0.7);
        }

        .after {
            background-color: rgba(79, 224, 240, 0.8);
        }

        .top,
        .bottom {
            width: 400px;
            height: 200px;
        }

        .top {
            background-color: rgba(255, 99, 71, 0.7);
        }

        .bottom {
            background-color: rgba(138, 43, 226, 0.7);
        }

        .left,
        .right {
            width: 200px;
            height: 300px;
        }

        .left {
            background-color: rgba(60, 179, 113, 0.5);
        }

        .right {
            background-color: rgba(210, 20, 147, 0.7);
        }

        /* 位置调整 */
        .after {
            /* 最后面z轴移动-200px */
            transform: translateZ(-200px);
        }

        .top {
            /* 上面先y轴反方向平移上去然后再向后折叠过去*/
            transform-origin: bottom;
            transform: translateY(-100%) rotateX(90deg);
        }
        .bottom {
            /* 下面先y轴正方向平移下去然后再向前折叠过去*/
            transform-origin: top;
            transform: translateY(300px) rotateX(-90deg);
        }
        .left {
            /* 左侧先x轴反方向平移过去然后再向右折叠过去*/
            transform-origin: right;
            transform: translateX(-200px) rotateY(-90deg);
        }
        .right {
            /* 右侧先x轴正方向平移过去然后再向左折叠过去*/
            transform-origin: left;
            transform: translateX(400px) rotateY(90deg);
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 立体盒子 -->
        <div class="mybox">
            <div class="face before">11</div>
            <div class="face after">12</div>
            <div class="face top">21</div>
            <div class="face bottom">22</div>
           <div class="face left">31</div>
            <div class="face right">32</div> 
        </div>
    </div>
</body>

</html>
